package com.tjy.farmer.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.tjy.common.annotation.Log;
import com.tjy.common.core.controller.BaseController;
import com.tjy.common.core.domain.AjaxResult;
import com.tjy.common.enums.BusinessType;
import com.tjy.farmer.domain.FarmerInfo;
import com.tjy.farmer.service.IFarmerInfoService;
import com.tjy.common.utils.poi.ExcelUtil;
import com.tjy.common.core.page.TableDataInfo;

/**
 * 蜂农信息Controller
 * 
 * @author tjy
 * @date 2025-09-05
 */
@RestController
@RequestMapping("/farmer/farmer")
public class FarmerInfoController extends BaseController
{
    @Autowired
    private IFarmerInfoService farmerInfoService;

    /**
     * 查询蜂农信息列表
     */
    @PreAuthorize("@ss.hasPermi('farmer:farmer:list')")
    @GetMapping("/list")
    public TableDataInfo list(FarmerInfo farmerInfo)
    {
        startPage();
        List<FarmerInfo> list = farmerInfoService.selectFarmerInfoList(farmerInfo);
        return getDataTable(list);
    }

    /**
     * 导出蜂农信息列表
     */
    @PreAuthorize("@ss.hasPermi('farmer:farmer:export')")
    @Log(title = "蜂农信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, FarmerInfo farmerInfo)
    {
        List<FarmerInfo> list = farmerInfoService.selectFarmerInfoList(farmerInfo);
        ExcelUtil<FarmerInfo> util = new ExcelUtil<FarmerInfo>(FarmerInfo.class);
        util.exportExcel(response, list, "蜂农信息数据");
    }

    /**
     * 获取蜂农信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('farmer:farmer:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(farmerInfoService.selectFarmerInfoById(id));
    }

    /**
     * 新增蜂农信息
     */
    @PreAuthorize("@ss.hasPermi('farmer:farmer:add')")
    @Log(title = "蜂农信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FarmerInfo farmerInfo)
    {
        return toAjax(farmerInfoService.insertFarmerInfo(farmerInfo));
    }

    /**
     * 修改蜂农信息
     */
    @PreAuthorize("@ss.hasPermi('farmer:farmer:edit')")
    @Log(title = "蜂农信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FarmerInfo farmerInfo)
    {
        return toAjax(farmerInfoService.updateFarmerInfo(farmerInfo));
    }

    /**
     * 删除蜂农信息
     */
    @PreAuthorize("@ss.hasPermi('farmer:farmer:remove')")
    @Log(title = "蜂农信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(farmerInfoService.deleteFarmerInfoByIds(ids));
    }
}
